package com.wac.data.controller;


import com.wac.data.service.LikeService;
import com.wac.data.service.UserService;
import com.wac.data.utils.DataListUtil;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author beta
 * @since 2023-03-16
 */
@RestController
@RequestMapping("/like")
public class LikeController {

	private String userId = null;

	@Resource
	private LikeService likeService;
	@Resource
	private UserService userService;

	@RequestMapping("/add")
	public String toLike(String entityId, String type, HttpServletRequest request) {
		this.userId = userService.isUserLogin(new DataListUtil().getCookies(request));
		if (likeService.toLike(this.userId, entityId, type)) {
			return "1";
		}
		return "0";
	}

	@RequestMapping("/isLike")
	public String isLike(String entityId, HttpServletRequest request) {
		this.userId = userService.isUserLogin(new DataListUtil().getCookies(request));
		if (likeService.isLike(this.userId, entityId)) {
			return "1";
		}
		return "0";
	}

}

